/**
 * StringIdentifier.java copyright tidalinfo
 * Created on 2020年12月17日 下午3:25:33
 */
package xj.toolkit.util;

import java.io.Serializable;

import org.apache.commons.lang3.RandomStringUtils;

/**
 * @author <a href="xiaojiancao@tidalinfo.cn">xiaojian.cao</a>
 *
 */
public class StringIdentifier implements Identifier<String>, Serializable {

	private static final long serialVersionUID = -8963367769044601661L;

	public String value = RandomStringUtils.random(16);

	public StringIdentifier() {
	}

	public StringIdentifier(String value) {
		this.value = value;
	}

	@Override
	public String getValue() {
		return value;
	}

	@Override
	public void setVaule(String t) {
		this.value = t;
	}

	@Override
	public String valueAsString() {
		return value;
	}

	@Override
	public int valueAsInt() {
		throw new UnsupportedOperationException();
	}

	@Override
	public byte[] valueAsByte() {
		return this.value.getBytes();
	}

	@Override
	public Identifier<String> fromSrting(String id) {
		return new StringIdentifier(id);
	}

	@Override
	public Identifier<String> fromByte(byte[] bArray) {
		return new StringIdentifier(new String(bArray));
	}

	@Override
	public Identifier<String> fromInt(int id) {
		throw new UnsupportedOperationException();
	}

	@Override
	public int length() {
		return this.value == null ? 0 : this.value.length();
	}

}
